
//点击退出 退回登录页并清空本地存储
back()
checkToken()
async function getData() {
    const res = await axios.get('/dashboard')
    const { data: { data: { overview, year, salaryData, groupData, provinceData } } } = res
    console.log(groupData);
    fn1(overview)
    fn2(year)
    fn3(salaryData)
    fn4(groupData)
    fn5(provinceData)
    fn6(salaryData)
    // console.log(provinceData);

}
getData()
// 概览
function fn1(overview) {
    Object.keys(overview).forEach(item => {
        document.querySelector(`.${item}`).innerHTML = overview[item]
    })
}
//薪资趋势
function fn2(year) {
    const myChart = echarts.init(document.querySelector('#line'))
    const option = {
        title: {
            text: '2024黑马薪资趋势分布',
            left: 15,
            top: 10
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: year.map(item => item.month),
            axisLine: {
                lineStyle: {
                    type: 'dashed',
                    color: '#999'
                }
            }
        },
        yAxis: {
            type: 'value',
            splitLine: {
                lineStyle: {
                    type: 'dashed',
                    color: '#999'
                }
            },
            axisLine: {
                lineStyle: {
                    type: 'dashed',
                    color: '#999'
                }
            }
        },
        series: [
            {
                data: year.map(item => item.salary),
                type: 'line',
                areaStyle: {
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#aedafa' // 0% 处的颜色
                        }, {
                            offset: 1, color: '#e3eef8' // 100% 处的颜色
                        }],
                        global: false // 缺省为 false
                    }
                },
                smooth: true,
                symbolSize: 10,
                lineStyle: {
                    width: 4,
                    color:
                    {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 1,
                        y2: 0,
                        colorStops: [{
                            offset: 0, color: '#cee8fc' // 0% 处的颜色
                        }, {
                            offset: 1, color: '#5577f7' // 100% 处的颜色
                        }]
                    }
                }
            }
        ]
    };
    myChart.setOption(option)
}
//薪资分布
function fn3(salaryData) {
    const myChart = echarts.init(document.querySelector('#salary'))
    const option = {
        color: ['#ff9e04', '#2f99ff', '#00c1fd', '#01d896'],
        title: {
            text: '班级薪资分布',
            left: 15,
            top: 10
        },
        tooltip: {
            trigger: 'item',
            data: ['班级薪资分布']
        },
        legend: {
            bottom: '5%',
            left: 'center'
        },
        series: [
            {
                name: '班级薪资分布',
                type: 'pie',
                radius: ['45%', '65%'],
                avoidLabelOverlap: false,
                itemStyle: {
                    borderRadius: 10,
                    borderColor: '#fff',
                    borderWidth: 2
                },
                label: {
                    show: false,
                    position: 'center'
                },
                labelLine: {
                    show: false
                },
                data: salaryData.map(item => {
                    return { value: (item.g_count + item.b_count), name: item.label }
                })
                // [
                //     { value: 1048, name: 'Search Engine' },
                //     { value: 735, name: 'Direct' },
                //     { value: 580, name: 'Email' },
                //     { value: 484, name: 'Union Ads' },
                // ]
            }
        ]
    };
    myChart.setOption(option)
}
//分组数据
function fn4(groupData) {
    let index = 1
    const btn = document.querySelector('#btns')

    btn.addEventListener('click', function (e) {
        if (e.target.classList.contains('btn')) {
            index = e.target.innerHTML
            document.querySelector('.btn-blue').classList.remove('btn-blue')
            e.target.classList.add('btn-blue')
        }
        fn(groupData, index)
    })
    fn(groupData, index)
}
function fn(groupData, index) {
    const myChart = echarts.init(document.querySelector('#lines'))
    const option = {
        xAxis: {
            type: 'category',
            data: groupData[index].map(item => item.name),
            axisLine: {
                lineStyle: {
                    type: 'dashed'
                }
            }
        },
        tooltip: {
            trigger: 'item',
            data: ['班级薪资分布']
        },
        yAxis: {
            type: 'value',
            splitLine: {
                lineStyle: {
                    type: 'dashed'
                }
            }
        },
        series: [
            {
                name: 'hope_salary',
                data: groupData[index].map(item => item.hope_salary),
                type: 'bar',
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0, color: '#00da98' // 0% 处的颜色
                    }, {
                        offset: 1, color: '#bef4e4' // 100% 处的颜色
                    }],
                }
            },
            {
                name: 'salary',
                data: groupData[index].map(item => item.salary),
                type: 'bar',
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0, color: '#1da4f4' // 0% 处的颜色
                    }, {
                        offset: 1, color: '#ceebfc' // 100% 处的颜色
                    }],
                }
            }
        ]
    };
    myChart.setOption(option)
}
//籍贯分布
function fn5(provinceData) {
    const myChart = echarts.init(document.querySelector('#map'))
    const dataList = [
        { name: '南海诸岛', value: 0 },
        { name: '北京', value: 0 },
        { name: '天津', value: 0 },
        { name: '上海', value: 0 },
        { name: '重庆', value: 0 },
        { name: '河北', value: 0 },
        { name: '河南', value: 0 },
        { name: '云南', value: 0 },
        { name: '辽宁', value: 0 },
        { name: '黑龙江', value: 0 },
        { name: '湖南', value: 0 },
        { name: '安徽', value: 0 },
        { name: '山东', value: 0 },
        { name: '新疆', value: 0 },
        { name: '江苏', value: 0 },
        { name: '浙江', value: 0 },
        { name: '江西', value: 0 },
        { name: '湖北', value: 0 },
        { name: '广西', value: 0 },
        { name: '甘肃', value: 0 },
        { name: '山西', value: 0 },
        { name: '内蒙古', value: 0 },
        { name: '陕西', value: 0 },
        { name: '吉林', value: 0 },
        { name: '福建', value: 0 },
        { name: '贵州', value: 0 },
        { name: '广东', value: 0 },
        { name: '青海', value: 0 },
        { name: '西藏', value: 0 },
        { name: '四川', value: 0 },
        { name: '宁夏', value: 0 },
        { name: '海南', value: 0 },
        { name: '台湾', value: 0 },
        { name: '香港', value: 0 },
        { name: '澳门', value: 0 },
    ]
    dataList.forEach(item => {
        const res = provinceData.find(ele => {
            return ele.name.includes(item.name)
        })
        if (res) {
            item.value = res.value
        } else {
            item.value = 0
        }
    })
    const option = {
        title: {
            text: '籍贯分布',
            top: 10,
            left: 10,
            textStyle: {
                fontSize: 16,
            },
        },
        tooltip: {
            trigger: 'item',
            formatter: '{b}:{c}位学员',
            borderColor: 'transparent',
            backgroundColor: 'rgba(0,0,0,0.5)',
            textStyle: {
                color: '#fff',
            },
        },
        visualMap: {
            min: 0,
            max: 6,
            left: 'left',
            bottom: '20',
            text: ['6', '0'],
            inRange: {
                color: ['#ffffff', '#0075F0'],
            },
            show: true,
            left: 40,
        },
        geo: {
            map: 'china',
            roam: false,
            zoom: 1.0,
            label: {
                normal: {
                    show: true,
                    fontSize: '10',
                    color: 'rgba(0,0,0,0.7)',
                },
            },
            itemStyle: {
                normal: {
                    borderColor: 'rgba(0, 0, 0, 0.2)',
                    color: '#e0ffff',
                },
                emphasis: {
                    areaColor: '#34D39A',
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowBlur: 20,
                    borderWidth: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)',
                },
            },
        },
        series: [
            {
                name: '籍贯分布',
                type: 'map',
                geoIndex: 0,
                data: dataList,
            },
        ],
    }
    myChart.setOption(option)

}
//男女薪资分布
function fn6(salary) {
    const myChart = echarts.init(document.querySelector('#gender'))
    const datas = [
        salary.map(item => { return { name: item.label, value: item.b_count } }),
        salary.map(item => { return { name: item.label, value: item.g_count } })
    ]

    option = {
        title: [{
            text: '阅读书籍分布',
            left: 15,
            top: 10,
            textStyle: {
                color: '#999',
                fontWeight: 'normal',
                fontSize: 14
            }
        },
        {
            text: '男生',
            left: 'center',
            top: '43%',
            textStyle: {
                color: '#999',
                fontWeight: 'normal',
                fontSize: 14
            }
        }, {
            text: '女生',
            left: 'center',
            top: '83%',
            textStyle: {
                color: '#999',
                fontWeight: 'normal',
                fontSize: 14
            }
        }
        ],
        tooltip: {
            trigger: 'item'
        },
        series: datas.map(function (data, idx) {
            const top = idx * 40 + 10;
            return {
                type: 'pie',
                radius: [40, 60],
                top: top + '%',
                height: '33.33%',
                left: 'center',
                width: 400,
                itemStyle: {
                    borderColor: '#fff',
                    borderWidth: 1
                },

                data: data,
                color: ['#f9a103', '#329cff', '#00c0ff', '#01d896']
            };
        })
    };
    myChart.setOption(option)
}
// const Clearfix = document.querySelector('.clearfix')
// Clearfix.addEventListener('click', function (e) {
//     if (e.target.classList.contains('btn-square')) {
//         document.querySelector('.active').classList.remove('active')
//         e.target.classList.add('active')
//     }
// })